<template>
    <div class="addEditArticlePageCont">
      <div class='title'>当前位置：文章审核 / 审核文章内容</div>
      <div class="addEditArticlePageMian">
        <Form ref="formAddEditArticle" :label-width="110">
          <FormItem label="所属楼盘：">
            {{cityName}}
            <span> - </span>
            {{buildingName}}
          </FormItem>
          <FormItem label="文章标题：" prop="articleTitle">
            {{articleTitle}}
          </FormItem>
          <FormItem label="文章标签：" prop="articleTags">
            {{articleTags}}
          </FormItem>
          <FormItem label="正文：" prop="articleTags">
            <div v-html="articleContent"></div>
          </FormItem>
          <FormItem label="封面图：" class="FormItemUpload">
            <div class="demo-upload-list" v-for="(item, index) in fileList" :key="index">
              <img :src="item.url">
              <div class="demo-upload-list-cover">
                  <Icon type="ios-eye-outline" @click="handleView(item.url)"></Icon>
              </div>
            </div>
          </FormItem>
          <div class="footer" v-if="$route.query.type != 'View'">
            <Button type="primary" @click="addEditArticleSubmit">通过审核</Button>
            <Button @click="addEditArticleReset">驳回</Button>
          </div>
      </Form>
      </div>
      <!-- 图片放大 -->
      <Modal title="图片预览" v-model="imageVisible" :footerHide="true">
          <img :src="previewAddress" style="width: 100%">
      </Modal>
      <Modal
        v-model="reasonRejectionState"
        title="驳回理由"
        @on-cancel="reasonRejectionCancel" width="500" :mask-closable="false" :footerHide="true">
        <Form ref="reasonRejectionRef" :model="reasonRejectionForm" :rules="reasonRejectionRules" :label-width="100">
          <FormItem label="驳回理由：" prop="reasonRejectionVal">
            <Input type="textarea" :rows="3" v-model="reasonRejectionForm.reasonRejectionVal" placeholder="请输入驳回理由" style=" width: 100%;"></Input>
          </FormItem>
          <div class="footer">
            <Button @click="reasonRejectionCancel">取消</Button>
            <Button type="info" @click="reasonRejectionOk">确认</Button>
          </div>
        </Form>
      </Modal>
    </div>
</template>
<script>
  import { articleGet, articleRebut } from "@/api/materialManagement.js";
  export default {
    components: {

    },
    data() {
      return {
        previewAddress: '',
        imageVisible: false,
        reasonRejectionState: false,
        cityName: '',
        buildingName: '',
        articleTitle: '',
        articleTags: '',
        fileList: [],
        articleContent: '',
        reasonRejectionForm: {
          reasonRejectionVal: ''
        },
        reasonRejectionRules: {
          reasonRejectionVal: [
            { required: true, message: '请输入驳回理由', trigger: 'blur' },
            { max: 100, message: '不超过100个字符', trigger: 'blur' },
          ]
        }
      }
    },
    methods: {
      // 通过审核
      addEditArticleSubmit() {
        articleRebut({articleId: this.$route.query.articleId, auditStatus: 1}).then(res=>{
          this.$store.commit('deleteroutefun', '审核文章内容'+Math.random());
          this.$Message.success('审核文章内容成功!');
          this.$router.go(-1);
        }).catch(err=>{
          this.$Message.error(err)
        })
      },
      // 驳回
      addEditArticleReset() {
        this.reasonRejectionState = true
      },
      // 驳回理由
      reasonRejectionOk() {
        this.$refs.reasonRejectionRef.validate((valid) => {
          if (valid) {
            articleRebut({articleId: this.$route.query.articleId, auditStatus: 2, rebutReason: this.reasonRejectionForm.reasonRejectionVal}).then(res=>{
              this.$Message.success('审核文章内容驳回成功!');
              this.reasonRejectionState = false;
              this.$router.go(-1);
            }).catch(err=>{
              this.$Message.error(err)
            })
          }
        })
      },
      reasonRejectionCancel(){
        this.reasonRejectionState = false
        this.$refs.reasonRejectionRef.resetFields();
      },
      // 图片预览
      handleView(val) {
        this.previewAddress = val
        this.imageVisible = true
      },
      // 初始化获取数据
      initData() {
        articleGet({articleId: this.$route.query.articleId}).then(res=>{
          if(res) {
            this.cityName = res.cityName
            this.buildingName = res.buildingAlias
            this.articleTitle = res.articleTitle
            this.articleTags = res.labelType
            this.fileList = [{url: res.articleImage}]
            this.articleContent = res.articleContent
          }
        }).catch(err=>{
          this.$Message.error(err)
        })
      }
    },
    computed: {

    },
    created() {
      // 初始化获取数据
      this.initData()
    },
    activated() {

    },
    deactivated() {

    },
    mounted() {

    },
    watch: {
      // "$route"(to, from) {
      //   if(to.path == "######") {
      //     this.initData();
      //   }
      // }
    },
  }
</script>
<style lang="scss" scoped>
  .addEditArticlePageCont{
    .title{
        background-color: #f5f5f5;
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
        padding: 0 14px 10px;
    }
    .addEditArticlePageMian{
      margin-top: 16px;
      width: 800px;
    }
  }
  .footer{
    padding-top: 16px;
    text-align: center;
    button{
      width: 90px;
      margin: 0 10px;
    }
  }
  // 上传
  .demo-upload-list{
    display: inline-block;
    width: 60px;
    height: 60px;
    text-align: center;
    line-height: 60px;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    position: relative;
    box-shadow: 0 1px 1px rgba(0,0,0,.2);
    margin-right: 4px;
  }
  .demo-upload-list img{
    width: 100%;
    height: 100%;
  }
  .demo-upload-list-cover{
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,.6);
  }
  .demo-upload-list:hover .demo-upload-list-cover{
    display: block;
  }
  .demo-upload-list-cover i{
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin: 0 2px;
  }
  .FormItemUpload .ivu-form-item-content{
    display: flex;
  }
  .imageSize{
    display: inline-block;
    margin-left: 16px;
    vertical-align: top;
    padding-top: 16px;
  }
</style>
